/**
 * 修改CSS窗口
 */
Ext.namespace("Ext.ux.sysconfig");

Ext.ux.sysconfig.EditItemWindow = Ext.extend(Ext.Window, {
	
	title: '修改配置项对话框',
	width: 330,
	height: 120,
	layout: 'fit',
	plain : true,
	modal: true,
	border: false,

	itemKey: null,
	itemMemo: null,
	
	parentPanelId: null,
	detailPanel: null,
	ctx: null,

	initComponent:function(){
		Ext.ux.sysconfig.EditItemWindow.superclass.initComponent.call(this);
		
		var inputPanel = new Ext.form.FormPanel({
    		labelAlign: 'right',
    		labelWidth: 120,
       		frame: true
    	});
		
		
		if(this.itemKey == 'SYS_CONFIG_CSS'){
			inputPanel.add({
				xtype: 'sysCodeCombo',
                fieldLabel: this.itemMemo,
                hiddenName: this.itemKey,
                typeCode: 'AOS_SYSCONFIG_CSS',
                allowBlank: false
			});
		}
		else if(this.itemKey == 'SYS_CONFIG_HOMEPAGE'){
			inputPanel.add({
				xtype: 'basicCombo',
				fieldLabel: this.itemMemo,
                hiddenName: this.itemKey,
				url: this.ctx + '/org/at-homepage-config!getAllActive.action',
				allowBlank: false
			});
		}
		else if(this.itemKey == 'SYS_CONFIG_IS_CLUSTER'){
			inputPanel.add({
				xtype: 'twoItemCombo',
				itemType: 'boolean',
				fieldLabel: this.itemMemo,
				hiddenName: this.itemKey,
				allowBlank: false,
				value: 1
			});
		}
				
		
    	this.add(inputPanel); 
    	this.detailPanel = inputPanel;
    	
    	//功能按钮
    	this.addButton({
    		text: '&nbsp;&nbsp;保存',
			width: 90,
			iconCls: 'icon-middle-save',
			scale: 'medium',
			handler: this.save,
			scope: this
    	});
    	this.addButton({
    		text: '关闭窗口',
			width: 90,
			iconCls: 'icon-middle-cancel',
			scale: 'medium',
			handler: function(){
				this.close();
			},
			scope: this
    	});
	},
	
	//保存
    save: function(){
    	if(this.detailPanel.form.isValid()){
    		this.detailPanel.form.submit({
    			url: 'sys-config!save.action',
    			success: function(form, action) {
    				Ext.getCmp(this.parentPanelId).refresh();
    				this.close();
					Ext.Msg.alert('系统提示', '成功修改配置项！');
				},
				failure: function(form, action) {
					Ext.Msg.alert('系统提示', '修改配置项失败！');
				},
				params: {
					key: this.itemKey,
					value: this.detailPanel.form.findField(this.itemKey).getValue()
				},
				waitMsg : '正在保存数据，请稍候...',
				scope: this
    		});
    	}
    }
});